<?php
mysql_connect("localhost", "root", "");
mysql_select_db("vendor");
/*
$result = mysql_query("select * from category");
while($row = mysql_fetch_array($result)){
    echo $row['title'];
    echo "<br />";
}
*/

function multilevel($id, $n = '') 
{ 
    $rs1=mysql_query("select * from category where parent_id='$id'"); 
    if(mysql_num_rows($rs1)==0) return; 
    $n .= '--';
    while($row1=mysql_fetch_array($rs1)) 
    { 
        
        echo "<tr><td>$n".$row1['title']."</td></tr>"; 
        multilevel($row1['category_id'], $n); 
    } 
        //echo "</ul>"; 
} 

$rs=mysql_query("select * from category where parent_id='0'"); 
echo "<table border=1>"; 
while($row=mysql_fetch_array($rs)) 
{ 
    echo "<tr><td>".$row['title']."</td></tr>"; 
    multilevel($row['category_id']); 
} 
echo "</table>";
?>
